package com.gitee.hljdrl.utils.date;

import android.annotation.SuppressLint;
import android.text.TextUtils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

@SuppressLint("SimpleDateFormat")
public class DateUtil {

    public static final String fileName(long time) {
        Date _date = new Date(time);
       DateFormat datetimeDf = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
        return datetimeDf.format(_date);
    }

    public static final String makeTime() {
        Date _date = Calendar.getInstance().getTime();
        DateFormat datetimeDf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return datetimeDf.format(_date);
    }

    public static final String makeTimeHour(long time) {
        Date _date = new Date(time);
        DateFormat datetimeDf = new SimpleDateFormat("HH:mm");
        return datetimeDf.format(_date);
    }

    public static final String logTime(Date _date) {
        DateFormat datetimeDf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return datetimeDf.format(_date);
    }

    public static final String makeTime(long time) {
        Date _date = new Date(time);
        DateFormat datetimeDf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return datetimeDf.format(_date);
    }

    public static final String makeTime(long time,String format) {
        Date _date = new Date(time);
        DateFormat datetimeDf = new SimpleDateFormat(format);
        return datetimeDf.format(_date);
    }

    public static final String makeTimeDay() {
        Date _date = new Date(System.currentTimeMillis());
        DateFormat datetimeDf = new SimpleDateFormat("yyyy-MM-dd");
        return datetimeDf.format(_date);
    }

    public static boolean isDay(Date date) {
        if (date == null) {
            return false;
        } else {
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            int _hour = cal.get(11);
            return _hour >= 6 && _hour <= 17;
        }
    }

    public static boolean isNight(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int _hour = cal.get(11);
        return _hour < 6 && _hour > 18;
    }

    public static Date toDate(String time) {
        if (TextUtils.isEmpty(time)) {
            return null;
        } else {
            StringBuffer _buf = new StringBuffer();
            _buf.append(time);
            if (time.length() == 10) {
                _buf.append("000");
            }

            Date _date = new Date(Long.parseLong(_buf.toString()));
            return _date;
        }
    }

    public static long toTime(String time, long addTime) {
        if (TextUtils.isEmpty(time)) {
            return 0L;
        } else {
            StringBuffer _buf = new StringBuffer();
            _buf.append(time);
            if (time.length() == 10) {
                _buf.append("000");
            }

            Date _date = new Date(Long.parseLong(_buf.toString()) + addTime);
            return _date.getTime();
        }
    }

    public static long foramtPHPTime(String time) {
        if (TextUtils.isEmpty(time)) {
            return 0L;
        } else {
            StringBuffer _buf = new StringBuffer();
            _buf.append(time);
            if (time.length() == 10) {
                _buf.append("000");
            }

            try {
                return Long.parseLong(_buf.toString());
            } catch (Exception var3) {
                return 0L;
            }
        }
    }

    public static String formatDataPHP(String time, SimpleDateFormat format) {
        if (!TextUtils.isEmpty(time)) {
            StringBuffer _buf = new StringBuffer();
            _buf.append(time);
            if (time.length() == 10) {
                _buf.append("000");
            }

            Date _date = new Date(Long.parseLong(_buf.toString()));
            return format.format(_date);
        } else {
            return null;
        }
    }

    public static String formatDataTimeOutPHP(String time, SimpleDateFormat format, long _addTime) {
        if (!TextUtils.isEmpty(time)) {
            StringBuffer _buf = new StringBuffer();
            _buf.append(time);
            if (time.length() == 10) {
                _buf.append("000");
            }

            long _longTime = Long.parseLong(_buf.toString());
            Date _date = new Date(_longTime + _addTime);
            return format.format(_date);
        } else {
            return null;
        }
    }

    public static long formatTimePHP(long time) {
        String _strTime = String.valueOf(time);
        if (!TextUtils.isEmpty(_strTime)) {
            StringBuffer _buf = new StringBuffer();
            _buf.append(time);
            if (_strTime.length() == 10) {
                _buf.append("000");
            }

            Date _date = new Date(Long.parseLong(_buf.toString()));
            return _date.getTime();
        } else {
            return time;
        }
    }
}
